#ifndef CORE_ERROR_CODE_H_
#define CORE_ERROR_CODE_H_

#include <QObject>
#include <QString>

#include "zlbase/zlbase.h"

class CRet
{
public:
    CRet() :
        code_(0)
    {
    }

    explicit CRet(int32_t code) :
        code_(code)
    {
    }

    ~CRet()
    {
    }

    void operator=(const int32_t& code)
    {
        code_ = code;
    }

    int32_t code() const
    {
        return code_;
    }

    QString string() const
    {
        switch (code_)
        {
            case zl::zlbase::ZLResult_Fail:
                return QObject::tr("Fail");
            case zl::zlbase::ZLResult_Success:
                return QObject::tr("Success");
            case zl::zlbase::ZLResult_Unconnected:
                return QObject::tr("Unconnected");
            case zl::zlbase::ZLResult_OpenFailed:
                return QObject::tr("OpenFailed");
            case zl::zlbase::ZLResult_Closed:
                return QObject::tr("Closed");
            case zl::zlbase::ZLResult_WriteFailed:
                return QObject::tr("WriteFailed");
            case zl::zlbase::ZLResult_WriteTimeout:
                return QObject::tr("WriteTimeout");
            case zl::zlbase::ZLResult_ReadFailed:
                return QObject::tr("ReadFailed");
            case zl::zlbase::ZLResult_ReadTimeout:
                return QObject::tr("ReadTimeout");
            case zl::zlbase::ZLResult_InvalidData:
                return QObject::tr("InvalidData");
            case zl::zlbase::ZLResult_InvalidParams:
                return QObject::tr("InvalidParams");
            case zl::zlbase::ZLResult_InvalidDialUp:
                return QObject::tr("InvalidDiaUp");
            case zl::zlbase::ZLResult_InvalidBcc:
                return QObject::tr("InvalidBcc");
            case zl::zlbase::ZLResult_InvalidColumn:
                return QObject::tr("InvalidColumn");
            case zl::zlbase::ZLResult_UnmatchedColumn:
                return QObject::tr("UnmatchedColumn");
            case zl::zlbase::ZLResult_ExecutionFailed:
                return QObject::tr("ExecutionFailed");
            case zl::zlbase::ZLResult_BoxnumOutofRange:
                return QObject::tr("BoxnumOutofRange");
            default:
                return QObject::tr("unknown");
        }
    }

private:
    int32_t code_;
};

#endif  // CORE_ERROR_CODE_H_